window.addEventListener('load', () => {
    //获取元素
    const input = document.querySelectorAll('.form-container input')
    const label = document.querySelectorAll('.form-container label')
    const regist = document.querySelector('.regist')
    const uname = document.querySelector('[name="name"]')
    const lname = document.querySelector('[name="lastname"]')
    const uemail = document.querySelector('[name="email"]')
    const uphone = document.querySelector('[name="phone"]')
    const upwd = document.querySelector('[name="password"]')
    const rpwd = document.querySelector('[name="rpassword"]')
        //当输入框获取焦点时，改变样式，变true
    for (let i = 0; i < input.length; i++) {
        input[i].addEventListener('focus', () => {
            for (var j = 0; j < input.length; j++) {
                label[j].className = 'f-label'
                if (label[j].innerText == '国家或地区*' || input[j].value) {
                    label[j].className = 't-label'
                }
            }
            label[i].className = 't-label'
        })
    }
    //点击创建账户时，判断输入内容是否符合要求
    regist.onclick = function() {
        //阻止默认事件
        window.event.preventDefault()
        var reg = /^[a-zA-Z0-9]{4,16}$/
        if (!reg.test(uname.value)) {
            alert('昵称格式不正确,应为字母或数字，4-16位')
            return
        }
        var reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
        if (!reg.test(uemail.value)) {
            alert('邮箱格式不正确')
            return
        }
        var reg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
        if (!reg.test(uphone.value)) {
            alert('电话号格式不正确')
            return
        }
        var reg = /^.{6,16}$/
        if (!reg.test(upwd.value)) {
            alert('密码格式不正确，应为6-16位')
            return
        }
        if (upwd.value != rpwd.value) {
            alert('两次密码不一致')
            return
        }
        console.log(111111);
        setcookie('username', uname.value)
        setcookie('pwd', upwd.value)
        console.log('您已成功注册，快去登陆吧！！！');
        location.href = './login.html'
    }
})